home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / PowerManager DDK 1.0f1 / Interfaces&Libraries / Interfaces / DateTimeUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-08  |  13.4 KB  |  461 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        DateTimeUtils.h
  3.  
  4.      Contains:    International Date and Time Interfaces (previously in TextUtils)
  5.  
  6.      Version:    System 8.5
  7.  
  8.      DRI:        Julio Gonzalez
  9.  
  10.      Copyright:    © 1994-1999 by Apple Computer, Inc., all rights reserved.
  11.  
  12.      Warning:    *** APPLE INTERNAL USE ONLY ***
  13.                  This file may contain unreleased API's
  14.  
  15.      BuildInfo:    Built by:            Scott Johnson
  16.                  On:                    10/8/99 11:26 AM
  17.                  With Interfacer:    3.0d13   (MPW PowerPC)
  18.                  From:                DateTimeUtils.i
  19.                      Revision:        9
  20.                      Dated:            4/28/99
  21.                      Last change by:    DSL
  22.                      Last comment:    [2319482]  CarbonLib no longer supports IUxxxx.
  23.  
  24.      Bugs:        Report bugs to Radar component "System Interfaces", "Latest"
  25.                  List the version information (from above) in the Problem Description.
  26.  
  27. */
  28. #ifndef __DATETIMEUTILS__
  29. #define __DATETIMEUTILS__
  30.  
  31. #ifndef __CONDITIONALMACROS__
  32. #include <ConditionalMacros.h>
  33. #endif
  34.  
  35. #ifndef __MACTYPES__
  36. #include <MacTypes.h>
  37. #endif
  38.  
  39.  
  40.  
  41.  
  42. #if PRAGMA_ONCE
  43. #pragma once
  44. #endif
  45.  
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49.  
  50. #if PRAGMA_IMPORT
  51. #pragma import on
  52. #endif
  53.  
  54. #if PRAGMA_STRUCT_ALIGN
  55.     #pragma options align=mac68k
  56. #elif PRAGMA_STRUCT_PACKPUSH
  57.     #pragma pack(push, 2)
  58. #elif PRAGMA_STRUCT_PACK
  59.     #pragma pack(2)
  60. #endif
  61.  
  62. /*
  63.  
  64.     Here are the current routine names and the translations to the older forms.
  65.     Please use the newer forms in all new code and migrate the older names out of existing
  66.     code as maintainance permits.
  67.     
  68.     New Name                    Old Name(s)
  69.     
  70.     DateString                    IUDatePString IUDateString 
  71.     InitDateCache
  72.     LongDateString                IULDateString
  73.     LongTimeString                IULTimeString
  74.     StringToDate                String2Date
  75.     StringToTime                                
  76.     TimeString                    IUTimeString IUTimePString
  77.     LongDateToSeconds            LongDate2Secs
  78.     LongSecondsToDate            LongSecs2Date
  79.     DateToSeconds                Date2Secs
  80.     SecondsToDate                Secs2Date
  81.  
  82.  
  83.     Carbon only supports the new names.  The old names are undefined for Carbon targets.
  84.     This is true for C, Assembly and Pascal.
  85.     
  86.     InterfaceLib always has exported the old names.  For C macros have been defined to allow
  87.     the use of the new names.  For Pascal and Assembly using the new names will result
  88.     in link errors. 
  89.     
  90. */
  91.  
  92. enum {
  93.                                                                 /* Toggle results */
  94.     toggleUndefined                = 0,
  95.     toggleOK                    = 1,
  96.     toggleBadField                = 2,
  97.     toggleBadDelta                = 3,
  98.     toggleBadChar                = 4,
  99.     toggleUnknown                = 5,
  100.     toggleBadNum                = 6,
  101.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  102.     toggleErr3                    = 7,
  103.     toggleErr4                    = 8,
  104.     toggleErr5                    = 9
  105. };
  106.  
  107. enum {
  108.                                                                 /* Date equates */
  109.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  110.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  111.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  112.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  113.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  114.     validDateFields                = -1,
  115.     maxDateField                = 10
  116. };
  117.  
  118. enum {
  119.     eraMask                        = 0x0001,
  120.     yearMask                    = 0x0002,
  121.     monthMask                    = 0x0004,
  122.     dayMask                        = 0x0008,
  123.     hourMask                    = 0x0010,
  124.     minuteMask                    = 0x0020,
  125.     secondMask                    = 0x0040,
  126.     dayOfWeekMask                = 0x0080,
  127.     dayOfYearMask                = 0x0100,
  128.     weekOfYearMask                = 0x0200,
  129.     pmMask                        = 0x0400,
  130.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  131. };
  132.  
  133. enum {
  134.     eraField                    = 0,
  135.     yearField                    = 1,
  136.     monthField                    = 2,
  137.     dayField                    = 3,
  138.     hourField                    = 4,
  139.     minuteField                    = 5,
  140.     secondField                    = 6,
  141.     dayOfWeekField                = 7,
  142.     dayOfYearField                = 8,
  143.     weekOfYearField                = 9,
  144.     pmField                        = 10,
  145.     res1Field                    = 11,
  146.     res2Field                    = 12,
  147.     res3Field                    = 13
  148. };
  149.  
  150. typedef SignedByte                         LongDateField;
  151. enum {
  152.     shortDate                    = 0,
  153.     longDate                    = 1,
  154.     abbrevDate                    = 2
  155. };
  156.  
  157. typedef SInt8                             DateForm;
  158. enum {
  159.                                                                 /* StringToDate status values */
  160.     fatalDateTime                = 0x8000,                        /* StringToDate and String2Time mask to a fatal error */
  161.     longDateFound                = 1,                            /* StringToDate mask to long date found */
  162.     leftOverChars                = 2,                            /* StringToDate & Time mask to warn of left over characters */
  163.     sepNotIntlSep                = 4,                            /* StringToDate & Time mask to warn of non-standard separators */
  164.     fieldOrderNotIntl            = 8,                            /* StringToDate & Time mask to warn of non-standard field order */
  165.     extraneousStrings            = 16,                            /* StringToDate & Time mask to warn of unparsable strings in text */
  166.     tooManySeps                    = 32,                            /* StringToDate & Time mask to warn of too many separators */
  167.     sepNotConsistent            = 64,                            /* StringToDate & Time mask to warn of inconsistent separators */
  168.     tokenErr                    = 0x8100,                        /* StringToDate & Time mask for 'tokenizer err encountered' */
  169.     cantReadUtilities            = 0x8200,
  170.     dateTimeNotFound            = 0x8400,
  171.     dateTimeInvalid                = 0x8800
  172. };
  173.  
  174. typedef short                             StringToDateStatus;
  175. typedef short                             String2DateStatus;
  176.  
  177. struct DateCacheRecord {
  178.     short                             hidden[256];                /* only for temporary use */
  179. };
  180. typedef struct DateCacheRecord            DateCacheRecord;
  181.  
  182. typedef DateCacheRecord *                DateCachePtr;
  183.  
  184. struct DateTimeRec {
  185.     short                             year;
  186.     short                             month;
  187.     short                             day;
  188.     short                             hour;
  189.     short                             minute;
  190.     short                             second;
  191.     short                             dayOfWeek;
  192. };
  193. typedef struct DateTimeRec                DateTimeRec;
  194.  
  195. typedef SInt64                             LongDateTime;
  196.  
  197. union LongDateCvt {
  198.     SInt64                             c;
  199.     struct {
  200.         UInt32                             lHigh;
  201.         UInt32                             lLow;
  202.     }                                 hl;
  203. };
  204. typedef union LongDateCvt                LongDateCvt;
  205.  
  206. union LongDateRec {
  207.     struct {
  208.         short                             era;
  209.         short                             year;
  210.         short                             month;
  211.         short                             day;
  212.         short                             hour;
  213.         short                             minute;
  214.         short                             second;
  215.         short                             dayOfWeek;
  216.         short                             dayOfYear;
  217.         short                             weekOfYear;
  218.         short                             pm;
  219.         short                             res1;
  220.         short                             res2;
  221.         short                             res3;
  222.     }                                 ld;
  223.     short                             list[14];                    /*Index by LongDateField!*/
  224.     struct {
  225.         short                             eraAlt;
  226.         DateTimeRec                     oldDate;
  227.     }                                 od;
  228. };
  229. typedef union LongDateRec                LongDateRec;
  230.  
  231. typedef SInt8                             DateDelta;
  232.  
  233. struct TogglePB {
  234.     long                             togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  235.     ResType                         amChars;                    /*from 'itl0', but uppercased*/
  236.     ResType                         pmChars;                    /*from 'itl0', but uppercased*/
  237.     long                             reserved[4];
  238. };
  239. typedef struct TogglePB                    TogglePB;
  240.  
  241. typedef short                             ToggleResults;
  242.  
  243.  
  244. EXTERN_API( OSErr )
  245. InitDateCache                    (DateCachePtr             theCache)                            FOURWORDINLINE(0x2F3C, 0x8204, 0xFFF8, 0xA8B5);
  246.  
  247. EXTERN_API( StringToDateStatus )
  248. StringToDate                    (Ptr                     textPtr,
  249.                                  long                     textLen,
  250.                                  DateCachePtr             theCache,
  251.                                  long *                    lengthUsed,
  252.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF6, 0xA8B5);
  253.  
  254. EXTERN_API( StringToDateStatus )
  255. StringToTime                    (Ptr                     textPtr,
  256.                                  long                     textLen,
  257.                                  DateCachePtr             theCache,
  258.                                  long *                    lengthUsed,
  259.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF4, 0xA8B5);
  260.  
  261. EXTERN_API( void )
  262. LongDateToSeconds                (const LongDateRec *    lDate,
  263.                                  LongDateTime *            lSecs)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  264.  
  265. EXTERN_API( void )
  266. LongSecondsToDate                (const LongDateTime *    lSecs,
  267.                                  LongDateRec *            lDate)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  268.  
  269. EXTERN_API( ToggleResults )
  270. ToggleDate                        (LongDateTime *            lSecs,
  271.                                  LongDateField             field,
  272.                                  DateDelta                 delta,
  273.                                  short                     ch,
  274.                                  const TogglePB *        params)                                FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  275.  
  276. EXTERN_API( short )
  277. ValidDate                        (const LongDateRec *    vDate,
  278.                                  long                     flags,
  279.                                  LongDateTime *            newSecs)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  280.  
  281.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  282.                                                                                             #pragma parameter __D0 ReadDateTime(__A0)
  283.                                                                                             #endif
  284. EXTERN_API( OSErr )
  285. ReadDateTime                    (unsigned long *        time)                                ONEWORDINLINE(0xA039);
  286.  
  287.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  288.                                                                                             #pragma parameter GetDateTime(__A0)
  289.                                                                                             #endif
  290. EXTERN_API( void )
  291. GetDateTime                        (unsigned long *        secs)                                TWOWORDINLINE(0x20B8, 0x020C);
  292.  
  293.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  294.                                                                                             #pragma parameter __D0 SetDateTime(__D0)
  295.                                                                                             #endif
  296. EXTERN_API( OSErr )
  297. SetDateTime                        (unsigned long             time)                                ONEWORDINLINE(0xA03A);
  298.  
  299.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  300.                                                                                             #pragma parameter SetTime(__A0)
  301.                                                                                             #endif
  302. EXTERN_API( void )
  303. SetTime                            (const DateTimeRec *    d)                                    TWOWORDINLINE(0xA9C7, 0xA03A);
  304.  
  305.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  306.                                                                                             #pragma parameter GetTime(__A0)
  307.                                                                                             #endif
  308. EXTERN_API( void )
  309. GetTime                            (DateTimeRec *            d)                                    THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  310.  
  311. EXTERN_API( void )
  312. DateToSeconds                    (const DateTimeRec *    d,
  313.                                  unsigned long *        secs);
  314.  
  315.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  316.                                                                                             #pragma parameter SecondsToDate(__D0, __A0)
  317.                                                                                             #endif
  318. EXTERN_API( void )
  319. SecondsToDate                    (unsigned long             secs,
  320.                                  DateTimeRec *            d)                                    ONEWORDINLINE(0xA9C6);
  321.  
  322. #if CALL_NOT_IN_CARBON
  323. EXTERN_API( void )
  324. IUDateString                    (long                     dateTime,
  325.                                  DateForm                 longFlag,
  326.                                  Str255                 result)                                TWOWORDINLINE(0x4267, 0xA9ED);
  327.  
  328. EXTERN_API( void )
  329. IUTimeString                    (long                     dateTime,
  330.                                  Boolean                 wantSeconds,
  331.                                  Str255                 result)                                THREEWORDINLINE(0x3F3C, 0x0002, 0xA9ED);
  332.  
  333. EXTERN_API( void )
  334. IUDatePString                    (long                     dateTime,
  335.                                  DateForm                 longFlag,
  336.                                  Str255                 result,
  337.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  338.  
  339. EXTERN_API( void )
  340. IUTimePString                    (long                     dateTime,
  341.                                  Boolean                 wantSeconds,
  342.                                  Str255                 result,
  343.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  344.  
  345. EXTERN_API( void )
  346. IULDateString                    (LongDateTime *            dateTime,
  347.                                  DateForm                 longFlag,
  348.                                  Str255                 result,
  349.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  350.  
  351. EXTERN_API( void )
  352. IULTimeString                    (LongDateTime *            dateTime,
  353.                                  Boolean                 wantSeconds,
  354.                                  Str255                 result,
  355.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  356.  
  357. #define DateString(dateTime, longFlag, result, intlHandle) \
  358.          IUDatePString( dateTime, longFlag, result, intlHandle)
  359. #define TimeString(dateTime, wantSeconds, result, intlHandle) \
  360.          IUTimePString(dateTime, wantSeconds, result, intlHandle)
  361. #define LongDateString(dateTime, longFlag, result, intlHandle) \
  362.          IULDateString(dateTime, longFlag, result, intlHandle)
  363. #define LongTimeString(dateTime, wantSeconds, result, intlHandle) \
  364.          IULTimeString(dateTime, wantSeconds, result, intlHandle)
  365.  
  366. #if OLDROUTINENAMES
  367. #define String2Date(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  368.          StringToDate(textPtr, textLen, theCache, lengthUsed, dateTime)
  369. #define String2Time(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  370.          StringToTime(textPtr, textLen, theCache, lengthUsed, dateTime)
  371. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  372. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  373. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  374. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  375. #endif  /* OLDROUTINENAMES */
  376.  
  377. EXTERN_API_C( void )
  378. iudatestring                    (long                     dateTime,
  379.                                  DateForm                 longFlag,
  380.                                  char *                    result);
  381.  
  382. EXTERN_API_C( void )
  383. iudatepstring                    (long                     dateTime,
  384.                                  DateForm                 longFlag,
  385.                                  char *                    result,
  386.                                  Handle                 intlHandle);
  387.  
  388. EXTERN_API_C( void )
  389. iutimestring                    (long                     dateTime,
  390.                                  Boolean                 wantSeconds,
  391.                                  char *                    result);
  392.  
  393. EXTERN_API_C( void )
  394. iutimepstring                    (long                     dateTime,
  395.                                  Boolean                 wantSeconds,
  396.                                  char *                    result,
  397.                                  Handle                 intlHandle);
  398.  
  399. EXTERN_API_C( void )
  400. iuldatestring                    (LongDateTime *            dateTime,
  401.                                  DateForm                 longFlag,
  402.                                  char *                    result,
  403.                                  Handle                 intlHandle);
  404.  
  405. EXTERN_API_C( void )
  406. iultimestring                    (LongDateTime *            dateTime,
  407.                                  Boolean                 wantSeconds,
  408.                                  char *                    result,
  409.                                  Handle                 intlHandle);
  410.  
  411. #else
  412. EXTERN_API( void )
  413. DateString                        (long                     dateTime,
  414.                                  DateForm                 longFlag,
  415.                                  Str255                 result,
  416.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  417.  
  418. EXTERN_API( void )
  419. TimeString                        (long                     dateTime,
  420.                                  Boolean                 wantSeconds,
  421.                                  Str255                 result,
  422.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  423.  
  424. EXTERN_API( void )
  425. LongDateString                    (LongDateTime *            dateTime,
  426.                                  DateForm                 longFlag,
  427.                                  Str255                 result,
  428.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  429.  
  430. EXTERN_API( void )
  431. LongTimeString                    (LongDateTime *            dateTime,
  432.                                  Boolean                 wantSeconds,
  433.                                  Str255                 result,
  434.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  435.  
  436. #endif  /* CALL_NOT_IN_CARBON */
  437.  
  438.  
  439.  
  440.  
  441. #if PRAGMA_STRUCT_ALIGN
  442.     #pragma options align=reset
  443. #elif PRAGMA_STRUCT_PACKPUSH
  444.     #pragma pack(pop)
  445. #elif PRAGMA_STRUCT_PACK
  446.     #pragma pack()
  447. #endif
  448.  
  449. #ifdef PRAGMA_IMPORT_OFF
  450. #pragma import off
  451. #elif PRAGMA_IMPORT
  452. #pragma import reset
  453. #endif
  454.  
  455. #ifdef __cplusplus
  456. }
  457. #endif
  458.  
  459. #endif /* __DATETIMEUTILS__ */
  460.  
  461.